package General;
import java.util.InputMismatchException;
//import java.util.LinkedList;
import java.util.Scanner;


public class UI {

	public void programIntro()
	{
        //Precondition: none
        //Postcondition:Displays program introduction
            System.out.println("The Drums of war are sounding throughout the land.");
            System.out.println("Your rivals march against you and your allies are all but vanquished");
            System.out.println("Will you be but a mere footnote in the dusty tome that is time?");
            System.out.println("Or will you rise up to vanquish your FOES?!");
            System.out.println ("This is AGE OF MYTHOLOGY!\n");  
    }//end method programIntro

    public int getMenuOption(Player player)
    {
    //Precondition: none;
    //Postcondition: Display the the menu
    //                 Prompts user and returns the menu options
        int menuOption;
        System.out.println("              Age Of Mythology              ");
        System.out.println("What will you do? WHAT WILL YOU DOOOOOO "+player.getName()+"?!?!");
        System.out.println("1. Draw Action cards");
        System.out.println("2. Do something else");
        System.out.println("3. Do a third thing, unlike the other things.");
        System.out.println("4. Exit the BLOODY PROGRAM");
        menuOption = getValidNonNegInt("Enter a number: ");
        return menuOption;
    }//end method getMenuOption
    
    public void prompt(String[] options, Player player){
        System.out.println("              Age Of Mythology              ");
        System.out.println("What will you do? WHAT WILL YOU DOOOOOO "+player.getName()+"?!?!");
        for(int i = 0; i<options.length;i++){
        	System.out.println(i+". "+options[i]);        	
        }
    }
    
    public int getValidNonNegInt(String prompt)
    {
    //Precondition: Prompt is the prompt for the integer
    //Postcondition: Prompt for and return a non-negative integer
        Scanner input = new Scanner(System.in);
        int userInput=0;
        boolean failed = true;
        System.out.print(prompt);
        do {
            try{
                userInput=input.nextInt();//This method can throw an exception
                if (userInput>=0)
                    failed=false;
                else
                    System.out.print("Invalid non-negative integer. Please reenter");
            }//end try block
            catch (InputMismatchException ex){
                System.out.print("Invalid non-negative integer. Please reenter");
            }//end catch block
            input.nextLine();
        }while (failed);
            return userInput;
     }//end method getValidNonNegInt
    public int getBoundedInt(String prompt, int start, int end)
    {
    //Precondition: Prompt is the prompt for the integer
    //Postcondition: Prompt for and return a valid integer
        Scanner input = new Scanner(System.in);
        int userInput=0;
        boolean failed = true;
        System.out.print(prompt);
        do {
            try{
                userInput=input.nextInt();//This method can throw an exception
                if (userInput>=start && userInput <= end)
                    failed=false;
                else
                    System.out.print("Invalid input. Please reenter");
            }//end try block
            catch (InputMismatchException ex){
                System.out.print("Invalid input. Please reenter");
            }//end catch block
            input.nextLine();
        }while (failed);
            return userInput;
     }//end method getBoundedInt
    
    public int assignVictory(Player player){
    	int i = 0;
    	String[] menuOptions = new String[VictoryCards.values().length];
    	for(VictoryCards cards: VictoryCards.values()){
    		menuOptions[i] = cards.toString()+": "
    		+Bank.singletonBank.getVictory(cards);
    		//System.out.println(menuOptions[i]);
    		i++;
    	}
    	prompt(menuOptions, player);
    	return getBoundedInt("Please choose a Victory Card to place a cube onto",0,menuOptions.length-1);
    }
    public int drawCard(Player player){
    	//display current hand
    	displayHand(player);
    	//display options
    	String[] menuOptions = {"Random","Age","Attack","Build","Explore", "Gather", "Recruit", "Trade", "Pass"}; 
    	prompt(menuOptions, player);
    	return getBoundedInt("Please choose a type of card to draw" +
    			"\nPlease remember that you may not draw a permanant action card after you draw a random card",
    			0,menuOptions.length-1);
    }
    public int drawRandom(Player player){
    	displayHand(player);
    	String[] menuOptions = {"Draw Random", "Pass"};
    	prompt(menuOptions, player);
    	return getBoundedInt("What would you like to do? ",0,1);
    }
    public void notifyFullHand(Player player){
    	System.out.println(player.getName()+" your hand is full and you may not draw");
    }
    public void displayHand(Player player){
    	System.out.println("Hand Contnets: ");
    	for(int i = 0; i<player.handCount(); i++){
    		System.out.println(player.peekHand(i).toString());
    	}
    }
    public void notifyEmptyHand(Player player){
    	System.out.println(player.getName()+", it is recommended to have atleast 3 cards.");
    }
    public void displayResources(Resource a){
    	System.out.println(a.toString());
    }
    public void spoilageA(Player player, Resource before, Resource after){
    	System.out.println(player.getName()+" Previous funds:");
    	displayResources(before);
    	System.out.println(player.getName()+" Current funds:");    	
    	displayResources(after);
    }
    public void padOut(){
    	System.out.println("\n\n\n");
    }
}//end class UI
